<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############


$THEME->addBreadcrumb($this->adminUrl.'/new-javascript/', $this->lang('new_javascript'));



if(Antz_IntelliForm::submitted('create-js')){
    $error = false;
  
    $keyname = preg_replace('/[^a-zA-Z0-9]/', '', post('keyname'));
    $title = post('title');
    $js = $_POST['js'];
    $default = (int) post('default');
    $version = post('version');

    if(trim($keyname)==''){
        $error = true;
        JFX::addError($this->lang('invalid_keyname'));
    }

    if($version == 'v_all') $version = '';

    if($DB->countRows($CONFIG->dbprefix.'jfxjs_javascripts', "id = '{$keyname}'")>0){
        $error = true;
        JFX::addError($this->lang('keyname_already_registered'));
        JFX::addFormError('keyname');
    }

    if(!$error){
		$this->setFile($keyname, $js, $version);
        $this->updateContentLang('title', $keyname, $title, '*', '*');
        JFX::addSuccess($this->lang('success'));
    }

}








$versionOpts = array('v_all'=>$this->lang('v_all'));
foreach($this->browserVersions as $k=>$v){
    $versionOpts[$v] = $this->lang('v_'.$v);
}



$formFields = array(
    array(
        'type' => 'text',
        'name' => 'keyname',
        'value' => post('keyname'),
        'label' => $this->lang('keyname')
    ),
    array(
        'type' => 'text',
        'name' => 'title',
        'value' => post('title'),
        'label' => $this->lang('title')
    ),
    array(
        'type' => 'checkbox',
        'name' => 'default',
        'value' => '1',
        'checked' => post('default', '1'),
        'label' => $this->lang('default_for_new_pages')
    ),
    array(
        'type' => 'select',
        'name' => 'version',
        'value' => post('version'),
        'options' => $versionOpts,
        'label' => $this->lang('browser_version')
    ),
    array(
        'type' => 'code',
        'id' => 'jfxcssnew',
        'class' => 'javascript',
        'name' => 'js',
        'value' => post('js'),
        'label' => $this->lang('js')
    ),
    array(
        'type' => 'submit',
        'name' => 'submitBtn',
        'value' => $this->lang('submit'),
        'label' => '&nbsp;'
    )
);

echo JFX::makeRapidForm($formFields, $this->lang('new_legend'), 'create-js');


echo '<script type="text/javascript" language="JavaScript">CodePress.run();</script>';